using System;
using System.Collections;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Xml.XPath;


namespace Comdiv{
#if MONORAIL
    internal static partial class MainExtensionSet
    {
#else
    public static class EffectiveBooleanExtensions{
#endif
        public static bool yes(this object obj){
            if (null == obj) return false;
            if (obj is bool) return (bool) obj;
            if (obj is string) return !String.IsNullOrEmpty((string) obj);
            ;
            if (obj is DateTime) return !((DateTime) obj).isUndefined();
            
            if (obj is ValueType) return 0 != Convert.ToDouble(obj);
            if (obj is IEnumerable) {
				return ((IEnumerable)obj).Cast<object>().FirstOrDefault()!=null;
			}
            if (obj is XPathNodeIterator) return ((XPathNodeIterator) obj).Count != 0;
            return true;
        }

        public static bool no(this object obj){
            return !obj.yes();
        }

       

        public static bool yes<T>(this IEnumerable<T> enumerable){
            if (null == enumerable) return false;
            if (0 == enumerable.Count()) return false;
            return true;
        }
    }
}